Development & Contributing
This document provides comprehensive development and contribution guidance for the SuperSet Telegram Notification Bot. It covers local setup, testing, code standards, development tools, debugging and profiling, performance optimization, CI/CD, and extension strategies for adding new notification channels and data sources.
The project is organized as a modular Python application under the app/ directory with clear separation of concerns:
Core configuration and daemon utilities
Service layer for business logic
Servers for Telegram bot, webhook, and update orchestration
Data models and schemas
Tests and logs
Development and deployment assets
Diagram sources
Section sources
CLI entry point orchestrating commands for bot, scheduler, webhook, update, send, official, and daemon control
Centralized configuration with Pydantic settings and logging setup
Daemon utilities for Unix-style background processes
Service layer for database operations, Telegram notifications, and integrations
Notification runner coordinating dispatch across channels
Telegram bot server handling commands and user interactions
Key responsibilities and integration points are defined in the CLI and service wiring.
Section sources
The system follows a dependency-injected, modular architecture:
Data sources (SuperSet portal, emails, official website) feed structured data into MongoDB
Services encapsulate business logic and integrate with external APIs
Notification channels (Telegram, Web Push) consume unsent notices from storage
CLI and servers orchestrate execution and expose admin interfaces
Diagram sources
CLI and Command Orchestration#
The CLI defines subcommands for bot, scheduler, webhook, update, send, official, and daemon control. It sets up logging, supports daemon mode, and wires services for orchestrated execution.
Diagram sources
Section sources
Configuration and Logging#
Centralized settings management with Pydantic, environment loading, and configurable logging levels and destinations. Includes daemon-aware printing and PID file management.
Diagram sources
Section sources
Daemon Utilities#
Unix-style daemonization with PID file management, graceful stop, and status reporting. Ensures background processes detach cleanly and redirect output.
Diagram sources
Section sources
Database Service#
Encapsulates MongoDB operations for notices, jobs, placement offers, users, and policies. Provides helpers for existence checks, retrieval, and statistics.
Diagram sources
Section sources
Telegram Service#
Implements Telegram notifications with message chunking, formatting, and broadcasting capabilities. Integrates with a Telegram client wrapper.
Diagram sources
Section sources
Notification Runner#
Coordinates sending unsent notices across channels using dependency injection. Supports Telegram and Web Push, with optional NotificationService composition.
Diagram sources
Section sources
Telegram Bot Server#
Long-polling Telegram bot with command handlers for user registration, help, status, stats, and administrative commands. Integrates with services for DB, notifications, and stats.
Diagram sources
Section sources
Project metadata and dependencies are defined in pyproject.toml and requirements.txt
Development uses uv for dependency management and reproducible environments
Docker Compose provides a local MongoDB instance for development
Diagram sources
Section sources
Use daemon mode for background processes to reduce overhead and improve reliability
Chunk long Telegram messages to avoid rate limits and failures
Minimize database round-trips by batching operations and using aggregation where possible
Leverage caching for settings and enable logging levels appropriate to environment
Profile CPU and memory usage during heavy update cycles using built-in profiling tools
[No sources needed since this section provides general guidance]
Common issues and remedies:
Verify environment variables and MongoDB connectivity before running
Check daemon status and logs for background processes
Use verbose CLI mode for detailed logs
Inspect scheduler job registrations and intervals
Validate Telegram bot token and chat ID configuration
Section sources
Fork and branch: feature/your-feature-name or fix/issue-description
Develop with pytest for unit tests and flake8 for style checks
Commit with conventional messages (feat:, fix:, refactor:, docs:, test:)
Create Pull Request with checklist items addressed
Address reviewer feedback and ensure tests pass
Section sources
Adding a new notification channel:
Implement a channel-specific service following the INotificationChannel pattern
Integrate via NotificationRunner and CLI flags
Add tests and update documentation
Adding a new data source:
Create a client/service pair similar to SupersetClientService or PlacementService
Wire into update orchestration in main.py
Ensure idempotent persistence and event generation for notifications
Integrating additional LLM pipelines:
Extend LangGraph workflows in dedicated services
Maintain separation of concerns and inject dependencies
Section sources
Scheduled workflows run the bot hourly and scrape official data
Python version pinned to 3.11 in CI for stability
Secrets injected for Telegram, MongoDB, SuperSet credentials, and email access
Use uv caching for faster dependency installs in CI
Section sources
Local setup with uv sync and Docker Compose for MongoDB
Run pytest for unit tests and coverage
Use mocks for external services in tests
Follow AGENTS.md style and best practices
Section sources
Use safe_print for daemon-friendly output
Enable verbose logging via CLI flags
Employ pdb or IDE debuggers for interactive inspection
Profile code using cProfile for hotspots
Section sources
Python 3.12+ with type hints and docstrings
Organized imports, consistent naming, and class structure
Logging at appropriate levels and error handling patterns
Configuration via Pydantic settings with validation
Section sources
This guide consolidates local development, testing, contribution, and operational practices for the SuperSet Telegram Notification Bot. By following the documented workflows, standards, and extension patterns, contributors can reliably add features, integrate new channels, and maintain system performance and reliability.